#include "manandwoman.h"
#include <iostream>
using namespace  std;
Man::Man(QString name , int age, QString location, int salary)
    :Person(name, age, location, MALE){
    _salary = salary;
}

ostream& operator <<(ostream &os, Man &p){
    Person *per = static_cast<Person *>(&p);
    os << *per;
    os << "\tSalary:" << QString::number( p._salary).toStdString() << "\n";
    return os;
}

istream& operator >>(istream &is, Man &p){
    Person *per = static_cast<Person *>(&p);
    is >> (*per);
    p._salary = p.getInfoFromIstream(is).toInt();
    return is;
}

void Man::outPut2Console(){
    cout << *this;
}


///////////////////////////////////
Woman::Woman(QString name, int age, QString location, Range *pExpectedSalary,
             Range *pExpectedAge, QStringList ExpectedLocation)
    :Person(name, age, location, FEMALE){
    _pExpectedSalary = pExpectedSalary;
    _pExpectedAge = pExpectedAge;
    _expectedLocation = ExpectedLocation;
}

ostream& operator <<(ostream &os, Woman &p){
    Person *per = static_cast<Person *>(&p);
    os << *per;
    os << "\tExpectedSalary:" << p._pExpectedSalary->toString().toStdString() << "\n";
    os << "\tExpectedAge:" << p._pExpectedAge->toString().toStdString() << "\n";
    os << "\tExpectedLocation:" << p._expectedLocation.join(",").toStdString() << "\n";
    return os;
}

istream& operator >>(istream &is, Woman &p){
    Person *per = static_cast<Person *>(&p);
    is >> *per;    
    p._pExpectedSalary->FromString(p.getInfoFromIstream(is));
    p._pExpectedAge->FromString(p.getInfoFromIstream(is));
    p._expectedLocation = p.getInfoFromIstream(is).split(",");
    return is;
}

void Woman::outPut2Console(){
    cout << *this;
}

QString Woman::getConditionStr(){
    QString retStr = "";
    retStr.append(_pExpectedSalary->getConditionStr("salary"))
            .append("&&").append(_pExpectedAge->getConditionStr("age"));
    if(_expectedLocation.count() > 0){
        retStr.append("&&location=");
        QString locationStr = _expectedLocation.join("||location=");
        retStr.append(locationStr);
    }
    if(DEBUG){
        qDebug("%s\n", retStr.toStdString().data());
    }
    return retStr;
}
